﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using Prism.Games.GalEngine.Scripts.Data.SceneElements;
using Prism.Core;
using Prism.Core.WPF;
using Prism.Games.GalEngine.Scripts.Parser.Input;

namespace Prism.Games.GalEngine.Scripts.Parser
{
    public class EIParser : ISceneParser
    {
        public EIParser()
        {
            this.ImageBrush = Helper.GraphicBase.FindName(Helper.GraphicBase.GalUIFrame.GamingFrame, "ExpressionImage") as System.Windows.Media.ImageBrush;
        }

        public void Restart()
        {
            this.ImageBrush.ImageSource = null;
        }

        public void PresentObject(FunctionModel.SceneObject element)
        {
            if (element == null)
            {
                this.ImageBrush.ImageSource = null;
                return;
            }

            if (element is ExpressionImage)
            {
                var target = element as ExpressionImage;

                if (target.IsCached)
                {
                    this.ImageBrush.ImageSource = target.CacheStream.CreateBitmapImage();
                }
                else
                {
                    this.ImageBrush.ImageSource = null;
                    return;
                }
                //else
                //{
                //    if (target.PartUri != null)
                //    {
                //        using (var ms = Helper.Packer.GetPartSteam(target.PartUri))
                //        {
                //            this.ImageBrush.ImageSource = Helper.CreateBitmapImage(ms);
                //        }
                //    }
                //    else
                //    {
                //        this.ImageBrush.ImageSource = null;
                //    }
                //}
            }
        }

        public System.Windows.Media.ImageBrush ImageBrush { get; set; }
    }
}
